home *** CD-ROM | disk | FTP | other *** search
- Newsgroups: comp.lang.c
- Path: news.dcs.warwick.ac.uk!not-for-mail
- From: D.C.Molero@dcs.warwick.ac.uk (Daniel Castillo Molero)
- Subject: separate compilation
- X-Nntp-Posting-Host: angel
- Message-ID: <1996Mar2.164559.24931@dcs.warwick.ac.uk>
- Sender: news@dcs.warwick.ac.uk (Network News)
- Organization: Department of Computer Science, Warwick University, England
- Date: Sat, 2 Mar 1996 16:45:59 GMT
-
-
- Hello,
- thank you for looking at this message.
- My problem is the following:
- I had a program which creates a linked list and then prints it, and was
- working, but when I tried to separate it in 3 different files, and compile
- it using
- gcc file1.c file2.c file3.c
-
- it doesn't compile.
-
-
- file1.c
- -------
- /* this file is supposed to print the linked list pointed
- to by first_side.
- */
- #include <stdio.h>
- #include <stdlib.h>
-
- /* declare the structure side as extern to avoid having to redeclare it,
- since it is already declared in file2.c
- */
- extern struct side;
-
- int main(void) {
- struct side *tmp;
- /* first_side is declared in file2.c and points to the first element
- of the list.
- */
- extern struct side *first_side;
- /* print the three elements */
-
- for (tmp = first_side; tmp; tmp = tmp->next)
- printf("side: %d\n", tmp->a);
-
- return 0;
- }
-
-
- file2.c
- -------
-
- /* type of each element of the linked list */
- struct side {
- int a;
- struct side *next;
- };
-
- void store_side(struct side* i, struct side** first_side);
-
- void create_list(void)
- {
- struct side *i;
- struct side *first_side;
-
- /* insert first element */
- first_side = 0;
- i = malloc(1*sizeof(struct side));
- i->a = 0;
- store_side(i, &first_side);
-
- /* insert second element */
- i = malloc(1*sizeof(struct side));
- i->a = 1;
- store_side(i, &first_side);
-
- /* insert third elemenet */
- i = malloc(1*sizeof(struct side));
- i->a = 2;
- store_side(i, &first_side);
-
- }
-
-
- file3.c
- -------
-
- /* declare the structure side as extern, as in file1.c */
- extern struct side;
-
- /* insert a new element in the list */
- void
- store_side(struct side* i, struct side** first_side)
- {
- i->next = *first_side;
- *first_side = i;
- }
-
- ------------------------------------
-
- The errors that I get are the following
-
- prnlist.c:4: warning: useless keyword or type name in empty declaration
- prnlist.c: In function `main':
- prnlist.c:11: dereferencing pointer to incomplete type
- prnlist.c:12: dereferencing pointer to incomplete type
- inselem.c:2: warning: useless keyword or type name in empty declaration
- inselem.c: In function `store_side':
- inselem.c:8: dereferencing pointer to incomplete type
- crlist.c: In function `create_list':
- crlist.c:17: warning: assignment makes pointer from integer without a cast
- crlist.c:22: warning: assignment makes pointer from integer without a cast
- crlist.c:27: warning: assignment makes pointer from integer without a cast
-
-
- -----------------
-
- Thank you very much for any help.
- danny
-
- danmol@dcs.warwick.ac.uk
-
- --
- * Daniel Castillo. D.C.Molero@dcs.warwick.ac.uk *
-
-
-